<?php

/**
 * @Project NUKEVIET 3.0
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
 * @Createdate 2-9-2010 14:43
 */
if ( ! defined( 'NV_IS_FILE_LANG' ) ) die( 'Stop!!!' );

$dirlang = filter_text_input( 'dirlang', 'get', '' );
$page_title = $language_array[$dirlang]['name'] . " -> " . $lang_module['nv_admin_read'];
if ( $nv_Request->get_string( 'checksess', 'get' ) == md5( "deleteallfile" . session_id() ) )
{
    if ( ! empty( $dirlang ) )
    {
        $dirs = nv_scandir( NV_ROOTDIR . "/modules", $global_config['check_module'] );
        $err = 0;
        $array_filename = array();
        foreach ( $dirs as $module )
        {
            if ( file_exists( NV_ROOTDIR . "/modules/" . $module . "/language/admin_" . $dirlang . ".php" ) )
            {
                $arrcrt = nv_deletefile( NV_ROOTDIR . "/modules/" . $module . "/language/admin_" . $dirlang . ".php" );
                if ( $arrcrt[0] == 0 )
                {
                    $err = 1;
                }
                $array_filename[] = $arrcrt[1];
            }
            if ( file_exists( NV_ROOTDIR . "/modules/" . $module . "/language/" . $dirlang . ".php" ) )
            {
                $arrcrt = nv_deletefile( NV_ROOTDIR . "/modules/" . $module . "/language/" . $dirlang . ".php" );
                if ( $arrcrt[0] == 0 )
                {
                    $err = 1;
                }
                $array_filename[] = $arrcrt[1];
            }
            
            $blocks = nv_scandir( NV_ROOTDIR . "/modules/" . $module . "/language/", "/^block\.(global|module)\.([a-zA-Z0-9\-\_]+)\_" . $dirlang . "\.php$/" );
            foreach ( $blocks as $file_i )
            {
                $arrcrt = nv_deletefile( NV_ROOTDIR . "/modules/" . $module . "/language/" . $file_i );
                if ( $arrcrt[0] == 0 )
                {
                    $err = 1;
                }
                $array_filename[] = $arrcrt[1];
            }
        }
        if ( is_dir( NV_ROOTDIR . "/language/" . $dirlang ) )
        {
            $arrcrt = nv_deletefile( NV_ROOTDIR . "/language/" . $dirlang, true );
            if ( $arrcrt[0] == 0 )
            {
                $err = 1;
            }
            $array_filename[] = $arrcrt[1];
        }
        if ( $err == 0 )
        {
            $db->sql_query( "ALTER TABLE `" . NV_LANGUAGE_GLOBALTABLE . "_file` DROP `author_" . $dirlang . "`" );
            $db->sql_query( "ALTER TABLE `" . NV_LANGUAGE_GLOBALTABLE . "` DROP `lang_" . $dirlang . "`" );
            $db->sql_query( "ALTER TABLE `" . NV_LANGUAGE_GLOBALTABLE . "` DROP `update_" . $dirlang . "`" );
            $contents = "<br /><br /><p align=\"center\"><strong>" . $lang_module['nv_lang_deleteok'] . "</strong></p>";
        }
        else
        {
            $contents = "<br /><br /><p align=\"center\"><strong>" . $lang_module['nv_lang_delete_error'] . "</strong></p>";
        }
        nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['nv_lang_delete'], $dirlang . ' --> ' . $language_array[$dirlang]['name'], $admin_info['userid'] );
        $contents .= implode( "<br />", $array_filename );
        $contents .= "<meta http-equiv=\"Refresh\" content=\"10;URL=" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=setting\" />";
        include ( NV_ROOTDIR . "/includes/header.php" );
        echo nv_admin_theme( $contents );
        include ( NV_ROOTDIR . "/includes/footer.php" );
    }
}
Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "" );
exit();
?>